package org.example.diet_compass.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Archer_hui
 * @version 1.0
 * @Date 2025/2/28 9:58
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    /**
     * 设置静态资源映射
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 添加静态资源映射规则
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //用户上传头像的映射规则
        registry.addResourceHandler("/avatar/**").addResourceLocations("file:G:/diet_compass/back_end/avatar/");
        //前端访问banners的资源
        registry.addResourceHandler("/banners/**").addResourceLocations("classpath:/static/banners/");
        //前端访问食物图片的资源
        registry.addResourceHandler("/canteen1/**").addResourceLocations("classpath:/static/diets/canteen1/");
        //前端访问食物图片的资源
        registry.addResourceHandler("/canteen2/**").addResourceLocations("classpath:/static/diets/canteen2/");
        //前端访问食物图片的资源
        registry.addResourceHandler("/canteen3/**").addResourceLocations("classpath:/static/diets/canteen3/");
        //前端访问图标的资源
        registry.addResourceHandler("/icons/**").addResourceLocations("classpath:/static/icons/");
        //前端访问logo的资源
        registry.addResourceHandler("/logo/**").addResourceLocations("classpath:/static/logo/");
        //配置 knife4j 的静态资源请求映射地址
        registry.addResourceHandler("/doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
